#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<sys/mman.h>
#include<unistd.h>

int *p = NULL;
int color = 0xFFFF00; 

void setxy(int x,int y,int x1,int *p){
    for(int r = x; r <= x1;r++){
    	 *(p+r+y*800) = color;
    }
}

int main(void){
    int x,y;
    int lcd_fd = open("/dev/fb0",O_RDWR);
    if (-1 == lcd_fd)
    {
        perror("open() lcd failed\n");
        return -1;
    }
    else
    {
        printf("open() lcd success\n");
    }

    p = mmap(NULL,800*480*4, PROT_READ|PROT_WRITE, MAP_SHARED,lcd_fd,0);

    if (NULL == p)
    {
        perror("mmap() failed\n");
        return 0;
    }
    
    //设置黑色背景
    int color1 = 0x000000;
    for (y = 0; y < 480; y++)
    {
        for ( x = 0; x < 800; x++)
        {
            *(p+x+y*800) = color1;
        }
        
    }
    /*
    
    //正方形
    for(int u = 57;u < 120;u++){
    	setxy(57,u,120,p);
    }
    
    //三角形
    for(int u = 0;u < 100;u++){
    	setxy(220-u,u,220+u,p);
    }
    */
    //圆形
    /*
    int j;
    for(int u = 0;u < 100;u++){
    	j = (int)sqrt(100*100-(100-u)*(100-u));
    	setxy(400+u,u,400-u,p);
    }
    */
    /*
    for(int u = 200;u < 220;u++){
    	setxy(100+u*2,u,100-u*2,p);
    	printf("%d",u);
    }
    for(int u = 220;u < 240;u++){
    	setxy(100+u,u,100-u,p);
    	printf("%d",u);
    }
    for(int u = 240;u < 260;u++){
    	setxy(100+u,u,100-u,p);
    	printf("%d",u);
    	++u;
    	setxy(100+u,u,100-u,p);
    	printf("%d",u);
    }
    */
    close(lcd_fd);
}
